{__NOLAYOUT__}
<include file="Public/meta"/>
        
        

        <div class="container-fluid">
            <div class="row-fluid">
                    
<div class="btn-toolbar">
    <button class="btn btn-primary" id="submit"><i class="icon-save"></i> 提交</button>
    <!-- <a href="#myModal" data-toggle="modal" class="btn">删除</a> -->
  <div class="btn-group">
  </div>
</div>
<div class="well">
    
    <div id="myTabContent" class="tab-content">
      <div class="tab-pane active in" id="home">
    <form id="tab" method="post">
        <label>角色名称</label>
        <input type="text" value="" class="input-xlarge" id="role_name" name='role_name'>
        
        

        <label>角色权限</label>
        <volist name="list" id="vo">
          <ul>
            <input type="checkbox" name="auths[]" class="fir" value="{$vo.auth_id}" <if condition="$vo['auth_name'] eq 首页">disabled checked</if>>{$vo.auth_name}<br>
            <volist name="vo['child']" id="vol">
              <ul>
                <input type="checkbox" name="auths[]" class="sec" value="{$vol.auth_id}" >{$vol.auth_name}
                <volist name="vol['child']" id="voli">
                  <input type="checkbox" name="auths[]" class="thir" value="{$voli.auth_id}" >{$voli.auth_name}
                </volist>
                <br>
              </ul>
            </volist>
          </ul>
          <br>
          
        </volist>
        

        <button class="btn btn-primary" id="chkAll">全选</button>

        <button class="btn btn-primary" id="chkNone">全不选</button>

        <button class="btn btn-primary" id="invert">反选</button>

    </form>
      </div>
      
  </div>

</div>

<div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Delete Confirmation</h3>
  </div>
  <div class="modal-body">
    
    <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete the user?</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
    <button class="btn btn-danger" data-dismiss="modal">Delete</button>
  </div>
<!-- </div> -->
  <ul>
                    
    <input type="checkbox" name="auth_check" value="<?php echo $au['id'];?>" class='da' ><?php echo $au['authname'];?>
        
        <br>
        <?php if(isset($au['child'])){ foreach($au['child'] as $auc):?>
        <input type="checkbox" class='son' name="auth_check" value="<?php echo $auc['id'];?>" ><?php echo $auc['authname'];?>

        <?php endforeach ;}?>
        
        
      </br>
  </ul>


<script type="text/javascript">

  var chkAll = $("#chkAll");
  var chkNone = $("#chkNone");
  var invert = $("#invert");
  var check = $("input[type=checkbox]");
  var fir = $(".fir");
  var sec = $(".sec");
  var thir = $(".thir");


  //全选
  chkAll.click(function(){
    check.each(function(){
      $(this).attr('checked',true);
    })
    return false;
  })  

  //全不选
  chkNone.click(function(){
    check.each(function(){
      $(this).attr('checked',false);
    })
    $("input[value=1]").attr('checked',true);
    return false;
  })  
  //反选
  invert.click(function(){
    check.each(function(){
      var th = $(this).attr('checked');
      if(th){
        $(this).attr('checked',false);
      }else{
        $(this).attr('checked',true);
      }
    })
    $("input[value=1]").attr('checked',true);
    return false;
  })
  
  fir.click(function(){
    var th = $(this).attr('checked');
    if(th){
      $(this).siblings().children().attr('checked',true);
      // alert($(this)..val());
    }else{
      $(this).siblings().children().attr('checked',false);
    }
    
  })

  sec.click(function(){
    var th = $(this).attr('checked');
    if(th){
      $(this).parent().siblings().attr('checked',true);
      $(this).siblings().attr('checked',true);

    }else{
      $(this).siblings().attr('checked',false);
    }
  })

  thir.click(function(){
    var th = $(this).attr('checked');
    if(th){
      $(this).siblings().eq(0).attr('checked',true);
      $(this).parent().siblings().attr('checked',true);
    }
  })


  function role_name_blur(){
      var role_name = $('#role_name').val();
      if(role_name==''){
        layer.msg('角色名称必须！',{icon:2,time:1000});return false;
      }else{
        return true;
      }
  }

  


  $('#role_name').blur(function(){
      role_name_blur();
  })

 


  $("#submit").click(function(){
 

      //提交前确认信息无误
      if(role_name_blur()){
        
          $.post("",$("#tab").serialize(),function(msg){
              if(msg.code=='1'){
                layer.msg(msg.info,{icon:1,time:1000},function(index){
                  window.parent.location.reload();
                });

              }else{
                layer.msg(msg.info,{icon:2,time:1000});
                return false;
              }
          })
        
      }
      


      
  })
  
</script>